package com.mp.approvalreq.servlet.component;

import com.mp.approvalreq.service.ApprovalOperateServicePrx;
import com.mp.approvalreq.servlet.AbstractServlet;
import com.mp.approvalreq.util.ApprovalUtils;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import com.plusmoney.exception.RpcServerLogicalException;
import com.plusmoney.message.SuccessMsg;
import com.plusmoney.util.ParameterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author liuqi
 * @date 2018/9/18
 */
@WebServlet("/delComponentGroup")
public class DelComponentGroup extends AbstractServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            User user = getReqUser(req);
            if (!ApprovalUtils.isApprovalAdmin(user)) {
                throw new RpcServerLogicalException(1, "无权操作");
            }

            Integer componentGroupId = ParameterUtils.getIntegerParameter(req, "componentGroupId", true);
            ApprovalOperateServicePrx approvalOperateService = ServiceUtils.getApprovalOperateServicePrx();

            approvalOperateService.delComponentGroup(user.getCompanyId(), componentGroupId);

            printJson(resp, SuccessMsg.getDefaultMsg());
        } catch (Throwable e) {
            onThrowable(req, resp, e);
        }
    }
}
